package com.shierke.Ume.ui.activity.me

import android.content.Context
import android.graphics.Color
import android.os.Bundle
import android.view.ViewGroup
import android.widget.Toast
import androidx.recyclerview.widget.LinearLayoutManager
import com.shierke.Ume.R
import com.shierke.Ume.base.BaseActivity
import com.shierke.Ume.ui.adapter.me.BlackAdapter
import com.shierke.Ume.util.startActivity
import com.yanzhenjie.recyclerview.*
import kotlinx.android.synthetic.main.activity_black_list.*

/**
 * Create by Ybx
 * on 2020-10-26
 * Desribe:
 */
class BlackListActivity : BaseActivity() {

    companion object {
        fun startActivity(context: Context) {
            context.startActivity<BlackListActivity>()
        }
    }


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_black_list)
        setActivityTitleText(getString(R.string.me_setting_black_activity_title))

        var arr = arrayListOf<String>(
            "1",
            "1",
            "1",
            "1",
            "1",
            "1",
            "1",
            "1",
            "1",
            "1",
            "1",
            "1"
        )


        val blackAdapter = BlackAdapter(arr)


        val mItemMenuClickListener =
            OnItemMenuClickListener { menuBridge, position ->
                menuBridge.closeMenu()

                val direction = menuBridge.direction // 左侧还是右侧菜单。
                val menuPosition = menuBridge.position // 菜单在RecyclerView的Item中的Position。

                if (direction == SwipeRecyclerView.RIGHT_DIRECTION) {

                    blackAdapter.getList().removeAt(menuPosition)
                    blackAdapter.notifyItemRemoved(menuPosition)

                } else if (direction == SwipeRecyclerView.LEFT_DIRECTION) {

                }
            }


        var creator = SwipeMenuCreator { leftMenu, rightMenu, position ->
            val height = ViewGroup.LayoutParams.MATCH_PARENT
            val width = resources.getDimensionPixelSize(R.dimen.black_width)
            val deleteItem =
                SwipeMenuItem(this@BlackListActivity).setBackground(R.drawable.bg_black_item_del)
                    //.setImage(R.drawable.ic_action_delete)
                    .setText(getString(R.string.me_setting_black_delete))
                    .setTextSize(18)
                    .setTextColor(Color.WHITE)
                    .setWidth(width)
                    .setHeight(height)
            rightMenu!!.addMenuItem(deleteItem)// 添加菜单到右侧。
        }


        blackList.setOnItemMenuClickListener(mItemMenuClickListener)

        blackList.setSwipeMenuCreator(creator)

        blackList.apply {
            adapter = blackAdapter
            layoutManager = LinearLayoutManager(this@BlackListActivity)
        }

    }
}